<?php
/*
Plugin Name: WP-documents
Plugin URI: #
Description: This plgin allow to manage documents
Version: a
Author: Carmine Ricco
Author URI: http://www.syriusweb.com
License: GPL2
*/

require_once "config.php";


add_action('activate_plugin', 'doc_activate'); // quando attivo il plugin
function doc_activate() {		
	
	global $wpdb;		
	global $administrator;
		
	//$administrator->add_cap('???');			
}

add_action('deactivate_plugin', 'doc_deactivate'); // quando disattivo il plugin
function doc_deactivate() {				
	//do something else
}


add_action('init', 'doc_init');
function doc_init() {		
	doc_set_lang_dir();
}	

add_action('init', 'doc_init_styles');
function doc_init_styles() {		
	//do something here				
}


add_action( 'admin_init','doc_init_js');
function doc_init_js() {		
	wp_register_script('dateformat_js', plugins_url('/js/date.format.js',__FILE__));
	wp_enqueue_script('dateformat_js');	

	wp_register_script('datepicker_js', plugins_url('/js/datepicker.js',__FILE__));
	wp_enqueue_script('datepicker_js');		
}	

add_action("admin_menu", "doc_plugin_add_menu");	
function doc_plugin_add_menu() {		
	//do something here	
}
	

add_action( 'add_meta_boxes', 'doc_add_custom_box' );
add_action( 'save_post', 'doc_save_postdata' );


function doc_add_custom_box() {
	add_meta_box( 'expire_date', __( 'Date expire', DOCUMENTS_DOMAIN ), 'doc_date_expire_box', 'dlm_download' );
}

function doc_date_expire_box( $post ) {	
	$date_expire = get_post_meta( $post->ID, 'date_expire', true );		
	?>
	
	<div class="metabox-tabs-div">		
		
		<div class="tab1">			
			<table class="form-table">			
				<tr>
					<th><label for="date_expire"><?php echo __( 'Date expire', DOCUMENTS_DOMAIN )?></label></th>
					<td><input id="date_expire" name="date_expire" type="text" value="<?php echo $date_expire?>"> </td>
				</tr>									
			</table>
		</div>
		
	</div>
	
	<?php
}


function doc_save_postdata( $post_id ) {
	
	if ( $_REQUEST['post_type'] == 'dlm_download') {				
		update_post_meta($post_id, 'date_expire', $_POST['date_expire']);		
  	}	
  
}